package cn.handong.tool.设计模式.代理模式.动态代理;

//import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;

        import java.lang.reflect.Method;

public class UtilTool {

//    private static org.apache.log4j.Logger logger = Logger.getLogger(UtilTool.class.toString());

    public static Object getFieldValueByFieldName(String fieldName, Object object) {
        try {
            String firstLetter = fieldName.substring(0, 1).toUpperCase();
            String getter = "get" + firstLetter + fieldName.substring(1);
            Method method = object.getClass().getMethod(getter, new Class[] {});
            Object value = method.invoke(object, new Object[] {});
            return value;
        } catch (Exception e) {
            return null;
        }
    }

    public static void copyFieldsFromLongToDoubleBigDecimal(Object source, Object target, String... properties){
        for(String field : properties) {
            Integer l = (Integer) getFieldValueByFieldName(field, source);
            Integer b= 125;
//            Integer b1= l;

//            //获取当前属性的set方法
//            String setMethod1 = "set" + Character.toUpperCase(field.charAt(0)) + field.substring(1);
//            Method method1 = BeanUtils.findMethod(target.getClass(), setMethod1, Integer.class);

            //获取当前属性的set方法
            String setMethod = "set" + Character.toUpperCase(field.charAt(0)) + field.substring(1);
            Method method = BeanUtils.findMethod(target.getClass(), setMethod, Integer.class);

            // 执行set方法
            try {
                method.invoke(target, b);
//                method1.invoke(target,b1);
            } catch (Exception e) {
//                logger.error("copyFieldsFromLongToDoubleBigDecimal fail:" + field, e);
            }
        }
    }

    public static void changeNum(MemberPointAccountSearchResVo vo){
        vo.setNum(100);
    }
}
